import axios from 'axios'
import { Message } from 'element-ui'
// create an axios instance
const service = axios.create({
  // baseURL:'', // url = base url + request url
//   baseURL: 'http://' + getCurrentLocation(),
  // withCredentials: true, // send cookies when cross-domain requests
  timeout: 10000 // request timeout
})

// request 拦截器
service.interceptors.request.use(config => {
//   if(config.headers){
//     $.extend(config.headers,{Authorization:getToken()})
//   }else{
//     config.headers = {Authorization:getToken()}
//   }
  return config
}, error => {
  console.log(error)
  Promise.reject(error)
})

// response 拦截器
service.interceptors.response.use(response => {
  if (response.status === 200) {
    return response
  } else {
    Promise.reject()
  }
}, error => {
  Message({
    message: error.message,
    type: 'error',
    duration: 2 * 1000
  })
  return Promise.reject(error)
})
export default service